import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index';
import navList from './nav.js'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 固定的路由表
export const fixedRouter = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index.vue')
    },
    {
        path: '/',
        component: () =>
            import ('@/views/layout.vue'),
        children: [{
            path: '/main',
            component: () =>
                import ('@/views/home.vue'),
            meta: {
                title: '首页',
                roles: ['user', 'admin'],
                icon: 'el-icon-info'
            }
        }],
        redirect: '/main' //二级路由默认显示
    }, {
        component: () =>
            import ('@/views/404.vue'),
        path: '*',
    }
]

// 需要权限判断展示的路由
export const permissionRouter = navList
store.commit('SET_NAV', ...permissionRouter)


let router = new Router({
    routes: fixedRouter
})
export default router